package com.tongji.quickCRUDQ.exception;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.handler.SimpleMappingExceptionResolver;

public class AjaxExceptionResolver extends SimpleMappingExceptionResolver {

	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object o, Exception ex) {
		if (ex instanceof AjaxException == false)
			return null;
		response.setCharacterEncoding("UTF-8");
		StringBuffer json = new StringBuffer("{errorInfo:\"").append(ex.getMessage()).append("\"}");
		request.setAttribute("json", json.toString());

		return new ModelAndView("forward:/ajaxFailure.html");
	}

}
